#pragma once
#include "afxwin.h"

typedef struct tagBMP_INFO
{
	CRect   rc;
	HBITMAP hBmp;
	CBitmap cBmp;  //
	CDC     dc;   //DC
	BITMAPFILEHEADER bmfh;
	BITMAPINFO bmi;
	BYTE    *pBits;
};

class CPixLedCtrl :	public CWnd
{
	DECLARE_DYNAMIC(CPixLedCtrl)  
  
public:
	CPixLedCtrl();  
	virtual ~CPixLedCtrl(); 

public:
	BOOL m_bInitial;

	CRect m_rcWnd;

	int   m_nLed_Width;
	int   m_nLed_Height;

	char  m_szFont_Name[32];
	int   m_nFont_Size;
	int   m_nFont_Height;

	int   m_nRatio;

	CRect m_rcLed;

	tagBMP_INFO m_Bmp_Info_Raw;
	tagBMP_INFO m_Bmp_Info_Mem;

public:
	BOOL  InitDoubleBuffer(tagBMP_INFO& bmp_Info);
	BYTE* InitDoubleBuffer(CRect& rc, BITMAPFILEHEADER& bmfh, BITMAPINFO& bmi, CDC& dc, HBITMAP& hBmp, CBitmap& bmp);

	void  ResetDoubleBuffer();
	void  DestroyDoubleBuffer(CDC& dc, HBITMAP& hBmp, CBitmap& bmp);
	void  DestroyDoubleBuffer(tagBMP_INFO& bmp_Info);

	void  SetLedSize(int nLed_Width, int nLed_Height);
	void  LoadLedImage(LPCTSTR pszLedImage);

	void ResetMemDC();
	void PixelToMemDC(Bitmap& bmp, CDC& dc, CRect& rcSrc, CRect& rcDest);
public:
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);  
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);  
	afx_msg void OnPaint();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
  
protected:
	DECLARE_MESSAGE_MAP()  
  
public:
	BOOL Create(CRect rcLayout,CWnd *pParenWnd,UINT nID,DWORD dwStyle = WS_CHILD|WS_VISIBLE);     
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
};

